package com.example.jt_common;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.time.Duration;

@Service
public class RedisService {

    @Autowired
    StringRedisTemplate redisTemplate;

    public String getDataByKey(String key){
        ValueOperations<String,String> valueOperations = redisTemplate.opsForValue();
        String result = valueOperations.get(key);
        return result;
    }


    public void setData(String key,String value){
        ValueOperations<String,String> valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key,value);
    }

    public void setDataAndTime(String key,String value,Integer time){
        ValueOperations<String,String> valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key,value,Duration.ofSeconds(time));
    }

}
